#include<iostream>
#include<string>
using namespace std;
int n,m;
string ans;
int main()
{
	scanf("%d,%d",&n,&m);
	bool flag=0;
	if(n<0){
		n=-n;
		flag=1;
	}
	while(n){
		int k=n%m;
		if(k<10)ans+=(char)(k+'0');
		else ans+=(char)(k-10+'a');
		n/=m;
	}
	reverse(ans.begin(),ans.end());
	if(flag)ans="-"+ans;
	cout<<ans<<endl;
	return 0;
}
